package com.vcc.web.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.vcc.core.annotations.RestPack;
import com.vcc.core.exception.ProgramException;
import com.vcc.data.entity.User;
import com.vcc.data.entity.UserCard;
import com.vcc.service.client.vo.otp.ClientOtpVo;
import com.vcc.service.service.OtpService;
import com.vcc.service.service.UserCardService;
import com.vcc.service.service.UserService;
import com.vcc.web.core.util.UserUtil;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("otp")
public class OtpController {


    @Resource
    private OtpService otpService;
    @Resource
    private UserCardService userCardService;
    @Resource
    private UserService userService;

    @RestPack
    @GetMapping("/list")
    @SaCheckLogin
    public List<ClientOtpVo> paging(
            Long userCardId
    ) {
        User user = UserUtil.get();
        UserCard userCard = userCardService.getByIdOpt(userCardId).orElseThrow(() -> new ProgramException("用户卡不存在"));
        UserUtil.baseVerifyUser(
                UserUtil.getRole(),
                user.getId(),
                userCard.getUserId(),
                user.getParentId(),
                userService.getParentIdById(userCard.getUserId())
        );
        return otpService.listByUserCardId(
                userCardId
        );


    }


}
